/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 牛孟俊
 * Date: 2023-11-09
 * Time: 18:14
 */
public class HashBuck<K,V> {
    static class Node<K,V> {
        private K key;
        private V val;
        private Node<K,V> next;

        public Node(K key, V val) {
            this.key = key;
            this.val = val;
        }
    }

    public Node<K,V>[] array =(Node<K, V>[]) new Node[10];
    public int usedsize;

    public void put(K key,V val) {
        Node<K,V> node = new Node<>(key,val);
        int hash = key.hashCode();//返回的数字很大
        int index = hash % array.length;//需要将返回的数字控制为合理的位置
        Node<K,V> cur = array[index];
        while(cur != null) {
            if(cur.key.equals(key)) {
                //有一样的key则更新value
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
        //cur等于null,没有这个key，进行尾插或者头插   这里进行的是头插
        node.next = array[index];
        array[index] = node;

    }
}
